import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @Title: 区间合并问题
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/5 19:53
 * @description: 经典的区间合并
 */
public class 区间合并问题 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        interval[] t = new interval[n];

        for(int i = 0; i < n; ++ i ) {
            interval x = new interval();
            x.setL(sc.nextInt());
            x.setR(sc.nextInt());
            t[i] = x;
        }
        Arrays.sort(t, new Comparator<interval>() {
            @Override
            public int compare(interval o1, interval o2) {
                if(o1.getL() != o2.getL()) {
                    return o1.getL() - o2.getL(); // 从小到大 排序
                } else {
                    return o1.getR() - o2.getR();
                }
            }
        });
        int ret = 1; // 表示区间的个数
        int l = t[0].getL();
        int r = t[0].getR();
//        System.out.println("r = " + r);
        for(int i = 1; i < n; ++ i ) {
            if(t[i].getL() > r) {
                l = t[i].getL();
                r = t[i].getR();
                ret++;
            } else {
                l = Math.min(t[i].getL(), l);
                r = Math.max(t[i].getR(), r);
            }

        }
        System.out.println(ret);


    }
}
class interval {
    private int l;
    private int r;


    public interval() {
    }

    public interval(int l, int r) {
        this.l = l;
        this.r = r;
    }

    /**
     * 获取
     * @return l
     */
    public int getL() {
        return l;
    }

    /**
     * 设置
     * @param l
     */
    public void setL(int l) {
        this.l = l;
    }

    /**
     * 获取
     * @return r
     */
    public int getR() {
        return r;
    }

    /**
     * 设置
     * @param r
     */
    public void setR(int r) {
        this.r = r;
    }

    public String toString() {
        return "interval{l = " + l + ", r = " + r + "}";
    }
}
